package com.study.kt._00test.gson

import com.google.gson.JsonDeserializationContext
import com.google.gson.JsonDeserializer
import com.google.gson.JsonElement
import java.lang.NumberFormatException
import java.lang.reflect.Type

class IntAdapter : JsonDeserializer<Int> {
    override fun deserialize(json: JsonElement?, typeOfT: Type?, context: JsonDeserializationContext?): Int {
        if (json?.asString.equals("")) {
            return 0
        }

        try {
            return json!!.asInt
        } catch (e: NumberFormatException) {
            return 0
        }
    }
}